package org.spiderflow.config.loginInterceptor;//package org.spiderflow.config.loginInterceptor;
//
//import com.alibaba.fastjson.JSONObject;
//import org.spiderflow.common.redis.userinfo.RedisUserInfoUtil;
//import org.spiderflow.userinfo.bean.UserInfo;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.io.PrintWriter;
//
//public class SecurityInterceptor extends HandlerInterceptorAdapter {
//
//    @Autowired
//    RedisUserInfoUtil redisUserInfoUtil;
//
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
//            throws Exception {
//
//        UserInfo userInfo = redisUserInfoUtil.getUserByKey();
//        if(userInfo==null){
//                JSONObject responseJSONObject = new JSONObject();
//                responseJSONObject.put("success", "false");
//                responseJSONObject.put("msg", "您还未登录！");
//                response.setCharacterEncoding("UTF-8");
//                response.setContentType("application/json; charset=utf-8");
//                response.setHeader("Content-Type", "application/json;charset=UTF-8");
//                response.setHeader("Content-Disposition", null);
//                PrintWriter out = null;
//                try {
//                    out = response.getWriter();
//                    out.append(responseJSONObject.toJSONString());
//                } catch (IOException e) {
//                    e.printStackTrace();
//                } finally {
//                    if (out != null) {
//                        out.close();
//                    }
//                }
//        }
//
//        return false;
//    }
//}